#!/bin/bash

# xmake 三维重建服务构建脚本

set -e

echo "=== xmake 三维重建服务构建脚本 ==="

# 检查 xmake 是否安装
if ! command -v xmake &> /dev/null; then
    echo "错误: 未找到 xmake，正在安装..."
    wget https://xmake.io/shget.text -O - | bash
    export PATH="$HOME/.local/bin:$PATH"
fi

echo "xmake 版本: $(xmake --version)"

# 清理之前的构建
echo "清理之前的构建..."
xmake clean

# 配置项目
echo "配置项目..."
xmake f -p linux -a x64 -m release

# 安装依赖
echo "安装依赖包..."
xmake require opencv nlohmann_json cpp-httplib

# 构建项目
echo "构建项目..."
xmake -j$(nproc)

echo "=== 构建完成 ==="
echo "可执行文件位置: build/reconstruction_service"
echo ""
echo "运行方式:"
echo "  ./build/reconstruction_service"
echo "  ./build/reconstruction_service --help"
echo ""
echo "Docker 构建:"
echo "  docker build -f Dockerfile.xmake -t reconstruction-service-xmake ."
echo "  docker run -d -p 8000:8000 reconstruction-service-xmake"
echo ""
echo "Docker Compose:"
echo "  docker-compose -f docker-compose.xmake.yml up -d" 